﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.CharacterDevelopment.PerkObject
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using Helpers;
using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.CharacterDevelopment
{
  public sealed class PerkObject : PropertyObject
  {
    internal static void AutoGeneratedStaticCollectObjectsPerkObject(
      object o,
      List<object> collectedObjects)
    {
      ((MBObjectBase) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    public static MBReadOnlyList<PerkObject> All => Campaign.Current.AllPerks;

    public SkillObject Skill { get; private set; }

    public float RequiredSkillValue { get; private set; }

    public PerkObject AlternativePerk { get; private set; }

    public SkillEffect.PerkRole PrimaryRole { get; private set; }

    public SkillEffect.PerkRole SecondaryRole { get; private set; }

    public float PrimaryBonus { get; private set; }

    public float SecondaryBonus { get; private set; }

    public SkillEffect.EffectIncrementType PrimaryIncrementType { get; private set; }

    public SkillEffect.EffectIncrementType SecondaryIncrementType { get; private set; }

    public TroopUsageFlags PrimaryTroopUsageMask { get; private set; }

    public TroopUsageFlags SecondaryTroopUsageMask { get; private set; }

    public TextObject PrimaryDescription { get; private set; }

    public TextObject SecondaryDescription { get; private set; }

    public bool IsTrash => this.Name == null || this.Description == null || this.Skill == null;

    public PerkObject(string stringId)
      : base(stringId)
    {
    }

    public void Initialize(
      string name,
      SkillObject skill,
      int requiredSkillValue,
      PerkObject alternativePerk,
      string primaryDescription,
      SkillEffect.PerkRole primaryRole,
      float primaryBonus,
      SkillEffect.EffectIncrementType incrementType,
      string secondaryDescription = "",
      SkillEffect.PerkRole secondaryRole = SkillEffect.PerkRole.None,
      float secondaryBonus = 0.0f,
      SkillEffect.EffectIncrementType secondaryIncrementType = SkillEffect.EffectIncrementType.Invalid,
      TroopUsageFlags primaryTroopUsageMask = TroopUsageFlags.Undefined,
      TroopUsageFlags secondaryTroopUsageMask = TroopUsageFlags.Undefined)
    {
      this.PrimaryDescription = new TextObject(primaryDescription);
      this.SecondaryDescription = new TextObject(secondaryDescription);
      PerkHelper.SetDescriptionTextVariable(this.PrimaryDescription, primaryBonus, incrementType);
      TextObject description;
      if (secondaryDescription != "")
      {
        PerkHelper.SetDescriptionTextVariable(this.SecondaryDescription, secondaryBonus, secondaryIncrementType);
        description = GameTexts.FindText("str_string_newline_newline_string");
        description.SetTextVariable("STR1", this.PrimaryDescription);
        description.SetTextVariable("STR2", this.SecondaryDescription);
      }
      else
        description = this.PrimaryDescription.CopyTextObject();
      description.SetTextVariable("newline", "\n");
      this.Initialize(new TextObject(name), description);
      this.Skill = skill;
      this.RequiredSkillValue = (float) requiredSkillValue;
      this.AlternativePerk = alternativePerk;
      if (alternativePerk != null)
        alternativePerk.AlternativePerk = this;
      this.PrimaryRole = primaryRole;
      this.SecondaryRole = secondaryRole;
      this.PrimaryBonus = primaryBonus;
      this.SecondaryBonus = secondaryBonus;
      this.PrimaryIncrementType = incrementType;
      this.SecondaryIncrementType = secondaryIncrementType == SkillEffect.EffectIncrementType.Invalid ? this.PrimaryIncrementType : secondaryIncrementType;
      this.PrimaryTroopUsageMask = primaryTroopUsageMask;
      this.SecondaryTroopUsageMask = secondaryTroopUsageMask;
      this.AfterInitialized();
    }

    public override string ToString() => this.Name.ToString();
  }
}
